package com.six.apidemic.fragment.my;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.six.apidemic.R;
import com.six.apidemic.activity.LoginActivity;
import com.six.apidemic.activity.ScanHistoryActivity;
import com.six.apidemic.bean.LoginCallbackBean;
import com.six.apidemic.fragment.BaseFragment;
import com.six.apidemic.util.SpUtils;

/**
 * @author Administrator
 */
public class MyFragment extends BaseFragment implements View.OnClickListener {

    RelativeLayout rlModuleScanHistory;
    RelativeLayout rlModuleLogout;
    TextView textView26,textView27,textView28,textView29;

    @Override
    protected void initView(View view) {
        rlModuleScanHistory = view.findViewById(R.id.rlModuleScanHistory);
        rlModuleScanHistory.setOnClickListener(this);
        rlModuleLogout = view.findViewById(R.id.rlModuleLogout);
        rlModuleLogout.setOnClickListener(this);
        textView26 = view.findViewById(R.id.textView26);
        textView27 = view.findViewById(R.id.textView27);
        textView28 = view.findViewById(R.id.textView28);
        textView29 = view.findViewById(R.id.textView29);

        LoginCallbackBean.ResultBean.UserBean bean = (LoginCallbackBean.ResultBean.UserBean)
                SpUtils.getBean(getActivity(),"module_user_bean");
        if (bean != null) {
            textView26.setText(bean.getName());
            textView27.setText(bean.getSex());
            textView28.setText(bean.getMobile());
            textView29.setText(bean.getAddress());

            switch (bean.getType()){
                case "0":
                    rlModuleScanHistory.setVisibility(View.VISIBLE);
                    break;
                case "1":
                case "2":
                    rlModuleScanHistory.setVisibility(View.GONE);
                    break;
                default:
            }
        }
    }

    @Override
    protected int findLayoutId() {
        return R.layout.fragment_my;
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.rlModuleScanHistory){
            startActivity(new Intent(getActivity(), ScanHistoryActivity.class));
        }else if (id == R.id.rlModuleLogout){
            SpUtils.clear(getActivity());
            startActivity(new Intent(getActivity(), LoginActivity.class));
            getActivity().finish();
        }
    }
}
